﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;


public partial class main : System.Web.UI.MasterPage
{
    private static readonly ILog Log = LogManager.GetLogger(typeof(Utilities));
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["language"] == null)
        {
            Session.Add("language", DAO.Connection.DEFAULT_LANGUAGE.ToString());
            //Session.Timeout = 1;

        }
        if (Session["message"] != null && Session["message"] != "")
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script",
                "<script language='javascript'> $(document).ready(function () {ShowMessage('" + Session["message"] + "');}); </script>");
            Session["message"] = null;
            Session["message_type_css"] = null;
        }
        Log.Debug("Master page Load\n");

        string plainText = "Hello, World!";    // original plaintext
        string cipherText = DAO.GlobalSettings.Encrypt(plainText);
        //Response.Write(plainText + "<br>");
        //Response.Write(cipherText + "<br>");

        plainText = DAO.GlobalSettings.Decrypt(cipherText);
        //Response.Write(plainText);
    }

    protected override void OnError(EventArgs e)
    {
        HttpContext ctx = HttpContext.Current;

        Exception exception = ctx.Server.GetLastError();

        string errorInfo =
           "<br>Offending URL: " + ctx.Request.Url.ToString() +
           "<br>Source: " + exception.Source +
           "<br>Message: " + exception.Message +
           "<br>Stack trace: " + exception.StackTrace;

        ctx.Response.Write(errorInfo);

        // --------------------------------------------------
        // To let the page finish running we clear the error
        // --------------------------------------------------
        ctx.Server.ClearError();

        base.OnError(e);
        Response.Redirect("~/teerror.aspx");
    }
}
